package com.gis507.test.AISTest2;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class AisBean implements WritableComparable<AisBean>{


    private String mmsi;
    private String speed;
    private Long unixTime;
    private double Lon_d;
    private double Lat_d;

    public AisBean() {

    }

    public AisBean(String mmsi, String speed, Long unixTime, double lon_d, double lat_d) {
        this.mmsi = mmsi;
        this.speed = speed;
        this.unixTime = unixTime;
        Lon_d = lon_d;
        Lat_d = lat_d;
    }

    public String getMmsi() {
        return mmsi;
    }

    public void setMmsi(String mmsi) {
        this.mmsi = mmsi;
    }

    public String getSpeed() {
        return speed;
    }

    public void setSpeed(String speed) {
        this.speed = speed;
    }

    public Long getUnixTime() {
        return unixTime;
    }

    public void setUnixTime(Long unixTime) {
        this.unixTime = unixTime;
    }

    public double getLon_d() {
        return Lon_d;
    }

    public void setLon_d(double lon_d) {
        Lon_d = lon_d;
    }

    public double getLat_d() {
        return Lat_d;
    }

    public void setLat_d(double lat_d) {
        Lat_d = lat_d;
    }

    @Override
    public String toString() {
        return mmsi + ',' + speed + ',' + unixTime + "," + Lon_d + "," + Lat_d;
    }

    @Override
    public int compareTo(AisBean o) {
        if (this.unixTime > o.unixTime){
            return -1;
        }else{
            return 1;
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {

        dataOutput.writeUTF(mmsi);
        dataOutput.writeUTF(speed);
        dataOutput.writeLong(unixTime);
        dataOutput.writeDouble(Lon_d);
        dataOutput.writeDouble(Lat_d);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {

        this.mmsi = dataInput.readUTF();
        this.speed = dataInput.readUTF();
        this.unixTime = dataInput.readLong();
        this.Lon_d = dataInput.readDouble();
        this.Lat_d = dataInput.readDouble();

    }
}
